/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import Modelo.Modelo;
import Modelo.Clases.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author cltsmalc
 * ir escribiendo el item que ingreso en el jtable, no que lo consulte de la base
 */
public class AmigoJPanel extends javax.swing.JPanel {

    /**
     * Creates new form AmigoJPanel
     */
     int filaSeleccionada = 0;
     ArrayList lista = new ArrayList();
     
     
     Anciano anciano = new Anciano();
     
    public AmigoJPanel() {
        initComponents();
    }
    
    public AmigoJPanel(int width , int height) {
        initComponents();
         this.setSize(width, height);
        this.setVisible(true);
        
        
        List<Amigo> lista = Modelo.consultarAmigos();
        
         for(int i =0 ; i < lista.size();i++){

            //this.jTable1.setValueAt(lista.get(i).getIdAmigo(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getAsociacion(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
            //this.jTable1.setValueAt(lista.get(i).getDescripcion(), i, 6);
            //this.jTable1.setValueAt(lista.get(i).getCedula(), i, 7);
           
        }
         
       
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jEImagePanel1 = new recursos.JEImagePanel();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField5 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(923, 575));

        jEImagePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/magic-wind-blue.jpg"))); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Add.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jLabel3.setText("Descripcion:");

        jLabel7.setText("Estado:");

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "activo", "inactivo","eliminado" }));
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "masculino", "femenino" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel6.setText("Genero:");

        jLabel9.setText("Asociacion: ");

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });
        jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField4KeyTyped(evt);
            }
        });

        jLabel8.setBackground(new java.awt.Color(204, 255, 153));
        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel8.setForeground(new java.awt.Color(102, 102, 255));
        jLabel8.setText("Ingreso de  Amigo");

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png"))); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Trash_Delete.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1KeyTyped(evt);
            }
        });

        jLabel1.setText("Nombre:");

        jLabel2.setText("Apellido:");

        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField2KeyTyped(evt);
            }
        });

        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField3KeyTyped(evt);
            }
        });

        jLabel10.setText("Cedula:");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nombre", "Apellido", "Asociacion", "Cedula", "Estado"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField5KeyReleased(evt);
            }
        });

        jLabel4.setText("Anciano:");

        jButton2.setText("Seleccionar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton4.setBackground(new java.awt.Color(255, 255, 255));
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/buscar.png"))); // NOI18N

        javax.swing.GroupLayout jEImagePanel1Layout = new javax.swing.GroupLayout(jEImagePanel1);
        jEImagePanel1.setLayout(jEImagePanel1Layout);
        jEImagePanel1Layout.setHorizontalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(jButton1))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel6)))
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel7))
                        .addGap(29, 29, 29)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                            .addComponent(jComboBox3, 0, 187, Short.MAX_VALUE)
                            .addComponent(jComboBox1, 0, 187, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGap(109, 109, 109)
                                .addComponent(jButton5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 366, Short.MAX_VALUE)
                                .addComponent(jButton3))
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGap(180, 180, 180)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(64, 64, 64)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 527, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(19, 19, 19))))
            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addComponent(jLabel8)
                .addContainerGap(695, Short.MAX_VALUE))
        );
        jEImagePanel1Layout.setVerticalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel8)
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(7, 7, 7)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(jLabel4))
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton2)))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(75, 75, 75))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try{
        Amigo amigo = new Amigo(v.anciano.getIdAnciano(),jTextField1.getText(), jTextField2.getText()
                , jTextField4.getText(), jTextField3.getText(),  jComboBox1.getSelectedItem()+""
                ,jTextArea2.getText(), jComboBox3.getSelectedItem()+"", "");
       Modelo.guardar(amigo);
       
        }catch(Exception e){
        JOptionPane.showMessageDialog(null, "Datos no validos");
        }
       initComponents();
       
         
         List<Amigo> lista = Modelo.consultarAmigos();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
         //this.jTable1.setVisible(false);
         
     
        
         for(int i =0 ; i < lista.size();i++){

             this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getAsociacion(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
           
        }
        // this.jTable1.setVisible(true);
         this.setVisible(true);
         this.v.dispose();
      
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox3ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jTextField4KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyTyped
        /**
         * ********** valida que sea solo letras************
         */
        char caracter = evt.getKeyChar();
        if (Character.isDigit(caracter) == true) {
            evt.consume();
        }
    }//GEN-LAST:event_jTextField4KeyTyped
    int bandera = 0 ; 
    int id_amigo = -1 ;
    
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
        
        Amigo a = Modelo.consultarAmigo(this.jTable1.getValueAt(jTable1.getSelectedRow(), 3)+"");
        
          try{
              if(bandera == 0){
              if(a!=null){
                  id_amigo = a.getIdAmigo();
                  
              this.jTextField1.setText(a.getNombre());
              this.jTextField2.setText(a.getApellido());
              this.jTextField3.setText(a.getCedula());
              this.jTextField4.setText(a.getAsociacion());
             if(a.getGenero().equalsIgnoreCase("masculino")){
            this.jComboBox1.setSelectedIndex(0);
            }
            if(a.getGenero().equalsIgnoreCase("femenino")){
            this.jComboBox1.setSelectedIndex(1);
            }
            
            if(a.getEstado().equalsIgnoreCase("eliminado")){
            this.jComboBox3.setSelectedIndex(2);
                    }
            if(a.getEstado().equalsIgnoreCase("inactivo")){
            this.jComboBox3.setSelectedIndex(1);
                    }
            if(a.getEstado().equalsIgnoreCase("activo")){
            this.jComboBox3.setSelectedIndex(0);
                    }
            
            this.jTextArea2.setText(a.getDescripcion());
            bandera = 1 ;
            jLabel8.setText("Modificar");
            jButton1.setEnabled(false);
            jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/guardar.png")));
            
            
              }else{
                  JOptionPane.showMessageDialog(null, "Error al cargar los datos");
              }
              
          }else{
              
              Amigo amigo = Modelo.consultarAmigoID(id_amigo+"");
              
              a.setNombre(jTextField1.getText());
              a.setApellido(jTextField2.getText());
              a.setCedula(jTextField3.getText());
              a.setAsociacion(jTextField4.getText());
              a.setEstado(jComboBox3.getSelectedItem().toString());
              a.setGenero(jComboBox1.getSelectedItem().toString());
              a.setDescripcion(jTextArea2.getText());
                  
                  try{
              if(v.anciano.getIdAnciano() != null){
              
                  a.setIdAnciano(v.anciano.getIdAnciano());
                  
              }
                  }catch(Exception e){
                  
                  }
              
              Modelo.actualizar(a);
              
             
              
               initComponents();
       
         
         List<Amigo> lista = Modelo.consultarAmigos();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
         for(int i =0 ; i < lista.size();i++){
             this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getAsociacion(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
           
        }
         this.setVisible(true);
         
         
         bandera = 0 ;
         jButton1.setEnabled(true);
         jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png")));
         jLabel8.setText("Ingresar Amigo");
         JOptionPane.showMessageDialog(null, "Registro Acualizado correctamente");
              
              }
              
              
        }catch(Exception e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        String cedula = ""+this.jTable1.getValueAt(this.filaSeleccionada, 3 );
       
       Amigo a = Modelo.consultarAmigo(cedula);
       if(a != null){
       Modelo.eliminar(a);
       }
       
       
        List<Amigo> lista = Modelo.consultarAmigos();
        this.setVisible(false);
         this.removeAll();
         initComponents();
         for(int i =0 ; i < lista.size();i++){

           this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getAsociacion(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
           
        }
        // this.jTable1.setVisible(true);
         this.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
// TODO add your handling code here:
        /**
         * ********** valida que sea solo letras************
         */
        char caracter = evt.getKeyChar();
        if (Character.isDigit(caracter) == true || jTextField1.getText().length() >= 10) {
            evt.consume();

        }
    }//GEN-LAST:event_jTextField1KeyTyped

    private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyTyped
// TODO add your handling code here:
        /**
         * ********** valida que sea solo letras************
         */
        char caracter = evt.getKeyChar();
        if (Character.isDigit(caracter) == true || jTextField1.getText().length() >= 10) {
            evt.consume();

        }
    }//GEN-LAST:event_jTextField2KeyTyped

    private void jTextField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyTyped
// TODO add your handling code here:
        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9') || jTextField3.getText().length() >= 10)
                && (caracter != '\b' /*
                 * corresponde a BACK_SPACE
                 */)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_jTextField3KeyTyped

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
// TODO add your handling code here:
    this.filaSeleccionada = this.jTable1.getSelectedRow(); 
    this.lista.add(this.jTable1.getSelectedRow());
}//GEN-LAST:event_jTable1MouseClicked

private void jTextField5KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField5KeyReleased
// TODO add your handling code here:
    
    String c = this.jTextField5.getText();
    
    List<Amigo> lista = Modelo.consultarAmigosCoincidencias(c);
    
 //   System.out.println(lista.size());
    
    for(int i = 0 ; i < jTable1.getRowCount(); i++){
    
        this.jTable1.setValueAt("", i, 0);
        this.jTable1.setValueAt("", i, 1);
        this.jTable1.setValueAt("", i, 2);
        this.jTable1.setValueAt("", i, 3);
        this.jTable1.setValueAt("", i, 4);
    }
    for(int i = 0 ; i < lista.size(); i++){
    
        this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
        this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
        this.jTable1.setValueAt(lista.get(i).getAsociacion(), i, 2);
        this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
        this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
    }
    
    
}//GEN-LAST:event_jTextField5KeyReleased

 Seleccionar v ;
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    
     v = new Seleccionar();
    v.setVisible(true);
    
    
}//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox3;
    private recursos.JEImagePanel jEImagePanel1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
}
